package dgopenai

import (
	"time"

	dgctx "github.com/darwinOrg/go-common/context"
	"github.com/sashabaranov/go-openai"
)

// GenerateContentTemplateProvider is an interface for providing generate content requests based on templates
var MyAigcTemplateProvider GenerateContentTemplateProvider

type GenerateContentTemplateProvider interface {
	GetGenerateContentRequest(ctx *dgctx.DgContext, templateName string, templateParams map[string]any, multiContent []openai.ChatMessagePart) (*GenerateContentRequest, error)
	GetChatGenerateContentRequest(ctx *dgctx.DgContext, templateName string) (*GenerateContentRequest, error)
}

// GenerateContentResponseProvider is an interface for saving generate content responses
var MyAigcResponseProvider GenerateContentResponseProvider

type GenerateContentResponseProvider interface {
	SaveGenerateContentResponse(ctx *dgctx.DgContext, templateName string, gcReq *GenerateContentRequest, gcResp *GenerateContentResponse,
		bizParams map[string]any, retry int, cost time.Duration, err error) error
	SaveChatGenerateContentResponse(ctx *dgctx.DgContext, templateName string, gcReq *GenerateContentRequest, gcResp *GenerateContentResponse,
		bizParams map[string]any, sessionId, messageId int64, retry int, cost time.Duration, err error) error
}

// ChatSessionProvider is an interface for providing chat session information
var MyChatSessionProvider ChatSessionProvider

type ChatSessionProvider interface {
	GetTemplateNameBySessionId(ctx *dgctx.DgContext, sessionId int64) (string, error)
}

// ChatMessageProvider is an interface for managing chat messages
var MyChatMessageProvider ChatMessageProvider

type ChatMessageProvider interface {
	FindChatMessages(ctx *dgctx.DgContext, sessionId int64) ([]*ChatMessage, error)
	SaveChatMessages(ctx *dgctx.DgContext, sessionId int64, messages []*ChatMessage) error
}

// FunctionCallProvider is an interface for handling function calls
var MyFunctionCallProvider FunctionCallProvider

type FunctionCallProvider interface {
	Call(ctx *dgctx.DgContext, functionCall *openai.FunctionCall, bizParams map[string]any) (string, error)
}
